#include <iostream>
using namespace std;

/*
    拷贝构造函数
        概念：用一个对象来初始化赋值给另一个新的对象的时候，会调用拷贝构造函数；常规赋值不会调用拷贝构造函数
            初始化赋值：Cat c1("Tom",15);   Cat c2 = c1;
            常规赋值：Cat c1("Tom",15);     Cat c2   c2 = c1;
        特点：
            程序员没有创建拷贝构造函数，编译器会自动创建一个拷贝构造函数
        语法：
            类名(const 类名 &ohter)
            {
                代码
            }
            将other的内容拷贝给本对象
        调用拷贝构造函数的写法：Cat c1("Tom",15);
            1. Cat c2 = c1;   
            2. Cat c2(c1);
            3. Cat c2 = Cat(c1);
            4. Cat *c2 = new Cat(c1);

*/

class Cat
{
public:
    Cat(string name,int age)
    {
        cout << "有参构造函数" << endl;
        this->name = name;
        this->age = age;
    }
    Cat()
    {
        cout << "无参构造函数" << endl;

    }
    Cat(const Cat &c)
    {
        cout << "拷贝构造函数" << endl;
        this->name = c.name;
        this->age = c.age;
    }
    void show()
    {
        cout << "猫的信息：" << endl;
        cout << "名字：" << this->name << endl;
        cout << "年龄：" << this->age << endl;
    }
private:
    string name;
    int age;


};


int main()
{
    Cat c1("Tom",15);
    Cat *c3 = &c1;
    Cat c2 = *c3;
    
    cout << "方法二:" << endl;
    Cat c4(c1);
    cout << "方法三:" << endl;
    Cat c5 = Cat(c1);
    cout << "方法四:" << endl;
    Cat *c6 = new Cat(c1);

    return 0;
}